/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package models.dao;

import java.sql.*;
import java.util.ArrayList;
import model.dao.util.MySqlDataAccessHelper;
import model.pojo.SachPOJO;

/**
 *
 * @author User
 */
public class SachDAO {
   public static ArrayList<SachPOJO> layDanhSachSachTheoDanhMuc(String maDanhMuc) throws SQLException {
      ArrayList<SachPOJO> ds = new ArrayList<SachPOJO>();
      String sql = String.format("SELECT * FROM SACH WHERE MADANHMUC='%s'", maDanhMuc);

      MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
      helper.open();
      ResultSet rs = helper.executeQuery(sql);
      while (rs.next()) {
         SachPOJO sach = new SachPOJO();
         sach.setMaSach(rs.getString("MaSach"));
         sach.setTenSach(rs.getString("TenSach"));
         sach.setTacgia(rs.getString("TacGia"));
        // sach.setSoLanXem(rs.getInt("SoLanXem"));
       //  sach.setSoTrang(rs.getInt("SoTrang"));
         sach.setGiaBan(rs.getDouble("GiaBan"));
         sach.setHinhAnh(rs.getString("HinhAnh"));
         sach.setSoLuong(rs.getInt("SoLuong"));
      //   sach.setGioiThieu(rs.getString("GioiThieu"));
         sach.setMaDanhMuc(rs.getString("MaDanhMuc"));

         ds.add(sach);
      }
      helper.close();
      return ds;
   }
}
